package core.proto.annotation;

import org.jdesktop.swingx.mapviewer.GeoPosition;

import core.proto.Util;

import de.jaret.util.date.JaretDate;
import static app.constants.CollabVizConstants.*;

public class TimelineAnnotationModel extends AnnotationModel {

	public enum IntervalRow {
		// Whether this annotation belongs in the 
		// timeline row for morning hours or evening hours.
		MORNING,
		EVENING
	}
	
	private JaretDate start;
	private JaretDate end;
	private IntervalRow row;
	
	private String rowName;
	

	public TimelineAnnotationModel(JaretDate start, JaretDate end,  
			String userText, String docKey, IntervalRow row){ 
		
		super(userText, docKey, AnnotationLocation.TIMELINE);
		this.start = start;
		this.end = end;
		this.userText = userText;
		this.docKey = docKey;
		this.row = row;
	}
	
	public JaretDate getStart() {
		return start;
	}

	public void setStart(JaretDate start) {
		this.start = start;
	}

	public JaretDate getEnd() {
		return end;
	}

	public void setEnd(JaretDate end) {
		this.end = end;
	}
	
	public TimelineAnnotationModel(String[] tokens) {
		super(tokens);
		this.start = new JaretDate(tokens[3]);
		this.end= new JaretDate(tokens[4]);
		this.row = IntervalRow.valueOf(tokens[5]);
	}
	
	@Override
	public String toSaveString() {
		String base = super.toBaseSaveString();
		String custom = Util.joinString(ANNOTATION_DELIMITER, this.start.getDate().getTime(), this.end.getDate().getTime(), this.row);
		return String.format("%s%s%s", base, ANNOTATION_DELIMITER, custom) + "<END>";
	}
	
	public IntervalRow getRow() {
		return row;
	}
	
	public void setRowName(String name){
		rowName = name;
	}
	
	public String getRowName(){
		if(rowName != null){
			for(int i = 0; i < rowName.length(); i++){
				if(rowName.charAt(i) != ' '){
					rowName = rowName.substring(i);
					break;
				}
			}
		
			return rowName;
		}
		else{
			return "Timeline";
		}
	}
}
